var e = getApp();
const {
  getCodeList,
  createOrder,
  getOpenid
} = require('../../common/api/user')
const api = require('../../common/utils/request.js')

Component({
  properties: {
    show: {
      value: false,
      type: Boolean
    },
  },

  data: {
    taskName: ''
  },
  ready: function () {
    this.setData({
      taskName: '自动发布' + this.getCurrentFormattedTime()
    })

  },
  
  methods: {
    getCurrentFormattedTime() {
      var date = new Date();
      var year = date.getFullYear();
      var month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要+1
      var day = String(date.getDate()).padStart(2, '0');
      var hours = String(date.getHours()).padStart(2, '0');
      var minutes = String(date.getMinutes()).padStart(2, '0');
      var seconds = String(date.getSeconds()).padStart(2, '0');
      return `${year}${month}${day}${hours}${minutes}${seconds}`;
    },
    changeTaskName(e){
      console.log(e,'eeeeeeeeeee')
      this.setData({
        taskName: e.detail.value
      })
    },
    buyNow() {
      console.log(this.data.openid, 'this.data.openid')
      var _this = this;
      api.post(createOrder, {
        pt_id: e.globalData.ptId,
        uid: wx.getStorageSync('yz_uid'),
        type: 3, // 1充值积分2充值金币3购买套餐
        taocan_id: this.data.taocan_id,
        pay_type: 1, //1微信支付2金币支付 （只有买套餐有金币支付）
        openid: this.data.openid
      }).then(res => {
        //成功时回调函数
        console.log(res.errno, 'getCodeList')
        if (res.errno == 0) {
         
        }
      }).catch(err => {
        //失败时回调函数
        console.log(err)
      })
    },
    changeTaocan(e) {
      console.log(e.currentTarget.dataset.index, 'eeeeeeeeeeeee')
      var index = e.currentTarget.dataset.index;
      var item = e.currentTarget.dataset.item;
      this.setData({
        current: index,
        price: item.price,
        taocan_id: item.id
      })
    },
    cancelPop: function (t) {
      console.log(t);
      this.triggerEvent("closeShow");
      this.setData({
        show: false,
      });
    },
    confirmPop(){
      if(this.data.taskName == ''){
        wx.showToast({
          title: '任务名称不能为空',
          icon: 'none'
        })
        return
      }
      this.triggerEvent("confirm",this.data.taskName);
    }
  }
});